package com.eduhzy.ttw.work.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.annotation.ScopeType;
import com.eduhzy.ttw.commonsdk.entity.MineClassData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.work.R;
import com.eduhzy.ttw.work.mvp.contract.PublishWorkContract;
import com.eduhzy.ttw.work.mvp.model.PublishWorkModel;
import com.eduhzy.ttw.work.mvp.model.entity.WorkSubmitData;
import com.eduhzy.ttw.work.mvp.ui.adapter.WorkUploadAdapter;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-3 10:07:39
 */
@Module
public class PublishWorkModule {
    private PublishWorkContract.View view;

    /**
     * 构建PublishWorkModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public PublishWorkModule(PublishWorkContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    PublishWorkContract.View providePublishWorkView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    PublishWorkContract.Model providePublishWorkModel(PublishWorkModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<WorkSubmitData> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    List<MineClassData> provideClassLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    @ScopeType()
    RecyclerView.LayoutManager provideLayoutManager() {
        return new GridLayoutManager(view.getActivity(), 4);
    }

    @ActivityScope
    @Provides
    @ScopeType(2)
    RecyclerView.LayoutManager provideClassLayoutManager() {
        return new GridLayoutManager(view.getActivity(), 3);
    }

    @ActivityScope
    @Provides
    WorkUploadAdapter providerAdapter(List<WorkSubmitData> lists) {
        return new WorkUploadAdapter(lists);
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<MineClassData, AutoBaseViewHolder> providerClassAdapter(List<MineClassData> lists) {
        return new BaseQuickAdapter<MineClassData, AutoBaseViewHolder>(R.layout.work_rv_item_class, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, MineClassData item) {
                helper.getView(R.id.btn_class).setSelected(item.isSelect());
                helper.setText(R.id.btn_class, item.getBjmc());
            }
        };
    }
}